package com.ff.xyh.feign.client.minio;

import com.ff.xyh.common.entity.result.ResultObject;
import com.ff.xyh.feign.config.FeignConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther FF
 * @Date 2022年 11月 16日
 * @Time 23:18
 */


@FeignClient(value = "api-minio", contextId = "MinioClient")
@RequestMapping(value = "/minio")
public interface MinioClient {

    /**
     * 获取指定目录文件列表
     */
    @GetMapping("get-filelist")
    ResultObject getAllFileList(String dir) throws Exception ;

    /**
     * 删除指定目录下的文件
     * @param dir
     * @return
     */
    @PostMapping("delete-dir")
    ResultObject deleteFilesInDir(
            @RequestParam(name = "dir", required = false) String dir) ;

    @PostMapping("delete-file")
    ResultObject deleteFile(
            @RequestParam(name = "objectName") String objectName) ;

    @GetMapping("download-file")
    void downloadFileInDir(
            @RequestParam(name = "objectName") String objectName,
            HttpServletResponse response) ;

    /**
     * 上传多个文件到指定的随机路径 并按顺序命名
     * @param files
     * @param path /files/(shop/travel)/uuid/
     * @return
     */
    @PostMapping("upload-files")
    ResultObject uploadFiles(
            @RequestPart(name = "files") MultipartFile[] files,
            @RequestParam(name = "path") String path) ;

    /**
     * 上传单个文件到指定文件位置
     * @param file
     * @param pathAndFilename /files/(shop/travel)/uuid/xxxx.png
     * @return
     */
    @PostMapping(value = "upload-file-path", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResultObject uploadFileToPath(
            @RequestPart(name = "file") MultipartFile file,
            @RequestParam(name = "pathAndFilename") String pathAndFilename) ;

    /**
     * 上传单个文件
     * @param file
     * @return
     */
    @PostMapping("upload-file")
    ResultObject uploadFile(
            @RequestBody MultipartFile file) ;



    /**
     * 头像上传
     * @param file
     * @param uuid 临时生成uuid
     * @return
     */
    @PostMapping("upload-avatar")
    ResultObject uploadAvatar(
            @RequestParam(name = "file", required = false) MultipartFile file,
            @RequestParam(name = "uuid", required = false) String uuid) ;

    /**
     * 帖子照片集上传
     * @param files
     * @param id 帖子id
     * @param postType 帖子类型
     * @return
     */
    @PostMapping("upload-files-post-imgs")
    ResultObject uploadFilesPostImgs(
            @RequestBody(required = false) MultipartFile[] files,
            @RequestParam(name = "id", required = false) String id,
            @RequestParam(name = "postType", required = false) String postType) ;

}
